#ifndef MEDIAENC_HD_H
#define MEDIAENC_HD_H
#include "ldCommInc.h"
#include "rtsp_demo.h"

#include <QWidget>
#include <QThread>
#include <QStringList>


#ifndef LINUX_AARCH64
#include "encffmpeg.h"
#else
#include "ench265.h"
#endif

typedef struct
{
     int                  nWidth;
     int                  nHeight;
     int                  nFps;
     uint64_t             nPts ;
     uint64_t             rtpPTS;
     int                  rtpPackSeq;
     rtsp_session_handle  rtspSession;
  #ifdef  LINUX_AARCH64
     stEncCtx             mppEnc;
  #else
     stFFMpegCtx          stFFMpegEncoder;
  #endif
}stEncRstpChn;

class MainWindow;

class MediaEncHD: public QThread
{
    Q_OBJECT
public:
    explicit  MediaEncHD(QObject *parent,bool isRtsp);
    ~MediaEncHD();


    void    run() override ;
    void    Stop();
    int     GetFps()
           {
               int nRes = m_nFps;
               m_nFps = 0;

               m_TmpFps = nRes;
               return nRes;
           }

    void    EncSendOneFrame(LD_RTSP_CHN rtspChn,uint8_t* pRGBFrame);

     MainWindow* pMainGUI;
signals:
     void  sig_recordFrame(int nChn,uint8_t*  pH26xFramePtr,int nLen);

public slots:

     void EncHDFrame(LD_RTSP_CHN rtspChn,uint8_t* pImgData,int nWidth,int nHeight,int nErrCode);

     void OnVideoRec(int startorstop,int nWidth,int nHeight);
     void ProcessFrame(stVFrame* frame);
private:
    QObject*            m_parent;
    //QThreadPool         m_varThreadPool;

    QString             m_AppPath;
    volatile  qint32    m_ThreadRun;
    volatile  qint32    m_Pause;
    int                 m_TmpFps;

    stEncRstpChn         m_nRtspChn[LD_RTSP_BUTT];

    int                  nRtspPort;
    char                 cRtspURL[STR_BUFF_LEN];


    rtsp_demo_handle     rtspInst;


    //VideoRec*           m_pVideoRec;


    volatile int         m_nFps;

    bool                   m_IsRecSpsPPS;
   //=============record==================
    bool                  m_IsVideoRec;

    int                   m_LostFrame;

    uint8_t               m_SpsPPS[256];

    uint8_t*              m_pRGBFrame;

    uint8_t*  pH265Packet; // = (uint8_t*)malloc(1920*1200*2);
    bool                 m_isRtsp;

    int                  m_FrameCnt;

};

#endif // MEDIAENC_H
